package cn.tedu.store.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.tedu.store.service.StudentService;

//动态代理类的辅助类
@Component
public class StudentProxyHandler implements 
		InvocationHandler{
	@Autowired
	private StudentService studentService;
	@Autowired
	private StudentAop studentAop;

	//获取动态代理类的对象
	public Object getObject(){
		//1.获取业务逻辑类的类加载器对象
		//2.获取业务逻辑类的接口对象
		//3.实现了InvocationHandler接口的实现类的对象
		return Proxy.newProxyInstance(
				studentService.getClass().getClassLoader(),
				studentService.getClass().getInterfaces(),
				this);
	}
	
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		studentAop.test();
		//通过反射调用业务逻辑类的方法
		Object o = method.invoke(studentService, args);
		//studentService.login(args);
		
		return o;
	}
}





